﻿namespace Contoso.ActiveDirectory {

    #region Usings
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.DirectoryServices;
    using System.Security.Principal;
    using System.Security;
    using System.DirectoryServices.AccountManagement;
    #endregion

    public class MethodParameters {

        public ActiveDirectoryAccessRule AccessRule { get; set; }

        /// <summary>
        /// For operations, the attribute name on which an operation will be performed
        /// </summary>
        public string AttributeName { get; set; }

        public object AttributeValue { get; set; }

        public object[] AttributeValueArray { get; set; }

        public AuthenticationTypes AuthenticationTypes {
            get {
                return ADDataAccess.GetAdjustedAuthenticationType(this.ServerNameOrAdjustedBindPath, authenticationTypes);
            }
        }
        private AuthenticationTypes authenticationTypes;

        /// <summary>
        /// For queries, the DN where the search will be performed.
        /// </summary>
        public string BaseDN { get; set; }

        public bool CacheResults { get; set; }

        public string Cn { get; set; }

        public string CreatedObjectDN { get; set; }

        public bool DestroyIntermediateResults { get; set; }

        public DomainConfiguration DomainInfo { get; set; }

        public bool DeleteCriticalSystemObject { get; set; }

        public bool DeleteChildren { get; set; }

        /// <summary>
        /// For move operations, the destination container object DN
        /// </summary>
        public string DestinationLocationDN { get; set; }

        public bool DisableCriticalSystemObject { get; set; }

        public string DisplayName { get; set; }

        public string DomainDN { get; set; }

        public string DomainNetbiosName { get; set; }

        public string EmailAddress { get; set; }

        public Dictionary<string, int> ExistingGroupMemberDNs { get; set; }

        /// <summary>
        /// Examples: Filter = "(objectCategory=person)(samAccountName=someValue*)";
        /// </summary>
        public string Filter { get; set; }

        public string GivenName { get; set; }

        public List<string> GroupMemberDNsToAdd { get; set; }

        public List<string> GroupMemberDNsToRemove { get; set; }

        public GroupTypeFlags GroupType { get; set; }

        public IdentityReference Identity { get; set; }

        /// <summary>
        /// For operations on integer attributes, the attribute value
        /// </summary>
        public int? IntegerAttributeValue { get; set; }

        public string LegacyExchangeDN { get; set; }

        public string Mail { get; set; }

        public string MailNickname { get; set; }

        public MSExchVersion MSExchVersion { get; set; }

        /// <summary>
        /// For operations, the DN of an object on which an operation will be performed.
        /// </summary>
        public string ObjectDN { get; set; }

        /// <summary>
        /// For operations, the DirectoryEntry of an object on which an operation will be performed.
        /// </summary>
        public DirectoryEntry ObjectDirectoryEntry { get; set; }

        /// <summary>
        /// For operations where a name is to be assigned
        /// </summary>
        public string ObjectName { get; set; }

        /// <summary>
        /// CreateAccount parameters
        /// </summary>
        public string OUDN { get; set; }

        public SecureString Password { get; set; }

        public List<string> ProxyAddresses { get; set; }

        /// <summary>
        /// Examples: PropertiesToGet = new string[] { "samAccountName", "displayName" }
        /// </summary>                      
        public string[] PropertiesToGet { get; set; }

        public PartitionScope PartitionScope { get; set; }

        public string SamAccountName { get; set; }

        /// <summary>
        /// The BaseDN that has been converted to an LDAP:// or GC:// path and has a server name embedded
        /// </summary>
        public string ServerNameOrAdjustedBindPath { get; set; }

        public IEnumerable<string> ShowInAddressBook { get; set; }

        /// <summary>
        /// For move operations, the source object DN
        /// </summary>
        public string SourceObjectDN { get; set; }

        public string Sn { get; set; }

        /// <summary>
        /// For operations on string attributes, the attribute value
        /// </summary>
        public string StringAttributeValue { get; set; }

        public string TargetAddress { get; set; }

        public bool TrimStringProperties { get; set; }

        #region Constructors
        public MethodParameters() {
            this.authenticationTypes = AuthenticationTypes.Secure | AuthenticationTypes.Sealing | AuthenticationTypes.Signing;
            this.PartitionScope = PartitionScope.LocalPartition;
            this.DestroyIntermediateResults = true;
        }

        public MethodParameters(string baseDN, AuthenticationTypes authenticationTypes = AuthenticationTypes.Secure | AuthenticationTypes.Sealing | AuthenticationTypes.Signing)
            : this() {
            this.authenticationTypes = authenticationTypes;
            this.BaseDN = baseDN;
        }
        #endregion
    }
}
